﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using ICSharpCode.SharpZipLib.Zip;
using Q1;

namespace twlib
{
    public enum UserPriviledges
    {
        CanUpload,
        CanDownload,
        CanModify,
        CanAccessRCon,
        FollowerSeeCode,
        FollowerSeeMedia,
        DesignerUpload,
        DesignerDownload
    }


    public static class PackageInstaller
    {
        public static bool InstallPackages()
        {
            try
            {
                foreach (string f in Directory.GetFiles(@"\temp\"))
                {
                    byte[] data = File.ReadAllBytes(f);
                    /*RRR.BasicQ1BinaryFormation bfmt = new RRR.BasicQ1BinaryFormation();
                    byte[] dpatch = bfmt.DePatch(data);

                    File.Delete(f);
                    File.WriteAllBytes(f, dpatch);*/

                    FastZip fz = new FastZip();
                    fz.ExtractZip(f, Environment.CurrentDirectory, "");
                }
                System.Diagnostics.Process.Start("tw.dat", "", null, "");
                Directory.Delete(@"\temp\", true);
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
    }

    namespace Notifications
    {
        public class Notification
        {
            private string user;
            private string text;
            private DateTime time;

            public string User { get { return user; } }
            public string Text { get { return text; } }
            public DateTime Time { get { return time; } }

            public Notification(string u, string t, DateTime tim)
            {
                user = u;
                text = t;
                time = tim;
            }

            public override string ToString()
            {
                string data = user + "|" + text + "|" + time.ToBinary().ToString();
                return data;
            }

            public static Notification Parse(string data)
            {
                string[] datas = data.Split('|');
                string user = datas[0];
                string text = datas[1];
                long time = long.Parse(datas[2]);

                return new Notification(user, text, DateTime.FromBinary(time));
            }
        }
    }
}
